package fr.mma.livraisonremote;

import java.io.IOException;

import org.apache.log4j.BasicConfigurator;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;

public final class RemplirUtilisateur {

	private RemplirUtilisateur() {
	};

	/**
	 * @param args
	 */
	public static void main(final String[] args) {
		BasicConfigurator.configure();
		final RemoteApiOptions options = new RemoteApiOptions().server("localhost", 8888).credentials("matthieu.mauny@gmail.com", "leslie29");
		final RemoteApiInstaller installer = new RemoteApiInstaller();
		try {
			installer.install(options);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			final DatastoreService dataStore = DatastoreServiceFactory.getDatastoreService();

			final Key key = KeyFactory.createKey("Developpeur", "ame");
			final Entity entity = new Entity(key);
			entity.setProperty("name", "Alan");
			entity.setProperty("nombreLivraison", 5);
			entity.setProperty("lastLivraison", Long.valueOf("1315526400000"));
			dataStore.put(entity);
		} finally {
			installer.uninstall();
		}

	}
}
